package com.lushu.chapitre1.dialogue.nodes
{
	import com.lushu.chapitre1.dialogue.api.INode;

	public class ComplexTextNode extends AbstractNode
	{	
		
		private var regExpPattern : RegExp = /\\n/g;
		
		public function ComplexTextNode()
		{
			type_ = "cText";
		}
		
		public override function toXML(level : int = 0) : String
		{
			var tabIndex : String ="";
			for(var j : int = 0; j < level; j++)
			{
				tabIndex+="\t";
			}
			var nodeXML : String = tabIndex+"<cText>";
			var child : INode;
			
			
			for(var i : int = 0; i < children.length; i++)
			{
				child = children[i];
				nodeXML += "\n"+child.toXML(level+1);
			}

			nodeXML += "\n"+tabIndex+"</cText>";
			return nodeXML;
		}
		
		public function switchToTextNode() : INode
		{
			var textNode : TextNode = children[0] as TextNode;
			parent.replaceChild(this, textNode);
				return textNode;
		}
		
		public override function setInformation(value : XML) : void
		{
			data_ = value.toString().replace(regExpPattern, "\n");
		}

	}
}